import Vue from 'vue';
import Router from 'vue-router';
import Store from '../store/index';
Vue.use(Router);
const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/dashboard',
    },
    {
      path: '/',
      component: () => import('../components/common/Home.vue'),
      meta: { title: '自述文件' },
      children: [

        {
          path: '/dashboard',
          name: "dashboard",
          component: () => import('../components/page/Dashboard.vue'),
          meta: { title: '系统首页' }
        },
        {
          path: '/courierCannelInTable',
          name: "courierCannelInTable",
          component: () => import('../components/page/dataTable/courierCannelInTable.vue'),
          meta: { title: '用户渠道管理' },
        },
        {
          path: '/agentFee',
          name: "agentFee",
          component: () => import('../components/page/dataTable/agentFee.vue'),
          meta: { title: '出货成本管理' },
        },
        {
          path: '/packageAccountTable',
          name: "packageAccountTable",
          component: () => import('../components/page/dataTable/packageAccountTable.vue'),
          meta: { title: '订单清账' },
        },
        {
          path: '/runFee',
          name: "runFee",
          component: () => import('../components/page/dataTable/runFee.vue'),
          meta: { title: '运营费用' },
        },
        {
          path: '/currencyExchangeRate',
          name: "currencyExchangeRate",
          component: () => import('../components/page/dataTable/currencyExchangeRate.vue'),
          meta: { title: '汇率管理' },
        },
        {
          path: '/restfulModelTable',
          name: "restfulModelTable",
          component: () => import('../components/page/dataTable/restfulModelTable.vue'),
          meta: { multiplexKey: "modelKey" },
        },
        {
          path: '/repositoryRegionManage',
          name: "repositoryRegionManage",
          component: () => import('../components/page/dataTable/repositoryRegionManage.vue'),
          meta: { title: '仓库区域管理' },
        },
        {
          path: '/packageClaimTable',
          name: "packageClaimTable",
          component: () => import('../components/page/dataTable/packageClaimTable.vue'),
          meta: { title: '包裹预报' },
        },
        {
          path: '/packageInTable',
          name: "packageInTable",
          component: () => import('../components/page/dataTable/packageInTable.vue'),
          meta: { title: '包裹录单' },
        },
        {
          path: '/repositoryInTable',
          name: "repositoryInTable",
          component: () => import('../components/page/dataTable/repositoryInTable.vue'),
          meta: { title: '包裹上架' },
        },
        {
          path: '/repositoryTable',
          name: "repositoryTable",
          component: () => import('../components/page/dataTable/repositoryTable.vue'),
          meta: { title: '库存管理' },
        },
        {
          path: '/sysuser',
          name: "sysuser",
          component: () => import('../components/page/dataTable/sysuser.vue'),
          meta: { title: '系统用户' },
        },
        {
          path: '/roleManage',
          name: "roleManage",
          component: () => import('../components/page/dataTable/roleManage.vue'),
          meta: { title: '系统角色管理' },
        },
        {
          path: '/appuser',
          name: "appuser",
          component: () => import('../components/page/dataTable/appuser.vue'),
          meta: { title: 'app用户' },
        },
        {
          path: '/orderprofitTable',
          name: "orderprofitTable",
          component: () => import('../components/page/dataTable/orderprofitTable.vue'),
          meta: { title: '订单核算' },
        },
        {
          path: '/income',
          name: "income",
          component: () => import('../components/page/dataTable/income.vue'),
          meta: { title: '收入' },
        },
        {
          path: '/profitTable',
          name: "profitTable",
          component: () => import('../components/page/dataTable/profitTable.vue'),
          meta: { title: '收支核算' },
        },
        {
          path: '/packageApplyOutTable',
          name: "packageApplyOutTable",
          component: () => import('../components/page/dataTable/packageApplyOutTable.vue'),
          meta: { title: '申请出货' },
        },
        {
          path: '/packageDeliverTable',
          name: "packageDeliverTable",
          component: () => import('../components/page/dataTable/packageDeliverTable.vue'),
          meta: { title: '订单出库' },
        },
        {

          path: '/userAccountCharge',
          name: "userAccountCharge",
          component: () => import('../components/page/dataTable/userAccountCharge.vue'),
          meta: { title: '用户充值管理' },
        },
        {
          path: '/agentManageTable',
          name: "agentManageTable",
          component: () => import('../components/page/dataTable/agentManageTable.vue'),
          meta: { title: '代理管理' },
        },
        {
          path: '/MsgCenter',
          component: () => import('../components/page/MsgCenter.vue'),
          meta: { title: '消息中心', noPermission: true }
        },

        {
          path: '/form',
          component: () => import('../components/page/BaseForm.vue'),
          meta: { title: '基本表单' }
        },
        {
          // 富文本编辑器组件
          path: '/editor',
          component: () => import('../components/page/VueEditor.vue'),
          meta: { title: '富文本编辑器' }
        },
        {
          // 图片上传组件
          path: '/upload',
          component: () => import(/* webpackChunkName: "upload" */ '../components/page/Upload.vue'),
          meta: { title: '文件上传' }
        },
        {
          // vue-schart组件
          path: '/charts',
          component: () => import('../components/page/BaseCharts.vue'),
          meta: { title: 'schart图表' }
        },

        {
          // 权限页面
          path: '/permission',
          component: () => import('../components/page/Permission.vue'),
          meta: { title: '权限测试', noPermission: true }
        },
        {
          path: '/404',
          component: () => import('../components/page/404.vue'),
          meta: { title: '404', noPermission: true, }
        },
        {
          path: '/403',
          component: () => import('../components/page/403.vue'),
          meta: { title: '403', noPermission: true, }
        },
        // {
        //   path: '/DragDialog',
        //   component: () => import('../components/page/DragDialog.vue'),
        //   meta: { title: 'DragDialog', noPermission: true, }
        // },
        {
          path: '/newsTable',
          name: "newsTable",
          component: () => import('../components/page/dataTable/newsTable.vue'),
          meta: { title: '新闻发布', }
        },
        {
          path: '/goodTypeManage',
          name: "goodTypeManage",
          component: () => import('../components/page/dataTable/goodTypeManage.vue'),
          meta: { title: '商品类型', }
        },
        {
          path: '/nationTable',
          name: "nationTable",
          component: () => import('../components/page/dataTable/nationTable.vue'),
          meta: { title: '国家管理', }
        },
        {
          path: '/userChargeQrCodeImage',
          name: "userChargeQrCodeImage",
          component: () => import('../components/page/dataTable/userChargeQrCodeImage.vue'),
          meta: { title: '小程序支付二维码', }
        },

        {
          path: '/channelTypeManage',
          name: "channelTypeManage",
          component: () => import('../components/page/dataTable/channelTypeManage.vue'),
          meta: { title: '渠道货物类型管理', }
        },

      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import(/* webpackChunkName: "login" */ '../components/page/Login.vue'),
      meta: { title: '登录', noLogin: true, }
    },
    {
      path: '*',
      redirect: '/404',
      meta: { noLogin: true, }
    }
  ]
});
//导航守卫,路径直接跳转的权限控制
router.beforeEach((to, from, next) => {
  if (to.meta.noLogin) {
    next()
  } else if (Store.state.token == null) {
    next("/login")
  } else if (to.meta.noPermission || !to.name || Store.state.limitsAuthority.isDefaultRole) {
    next()
  } else if (to.meta.multiplexKey && to.query[to.meta.multiplexKey]) {
    if (Store.state.limitsAuthority.menuDict[`${to.name}?${to.meta.multiplexKey}=${to.query[to.meta.multiplexKey]}`]) {
      next()
    } else {
      next("/403")
    }
  } else if (Store.state.limitsAuthority.menuDict[to.name]) {
    next()
  } else {
    next("/403")
  }

})

export default router
